<?php

/**
 * This is the model class for table "foto".
 *
 * The followings are the available columns in table 'foto':
 * @property integer $ft_id
 * @property string $ft_filename
 * @property integer $ft_kode
 */
class Foto extends CActiveRecord
{
	public $imgFoto;
	/**
	 * Returns the static model of the specified AR class.
	 * @return Foto the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'foto';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ft_filename', 'length', 'max'=>128),
			array('ft_kode', 'length', 'max'=>16),
			array('imgFoto','unsafe'),
			array('imgFoto','file','types'=>'jpg','maxSize'=>200000,'tooLarge'=>'Ukuran File terlalu besar'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ft_id, ft_filename, ft_kode', 'safe', 'on'=>'search'),
		);
	}
	public function beforeSave(){
		if($file=CUploadedFile::getInstance($this,'imgFoto')){
			$filename = date('YmdHis').Konstanta::filterWord($file->name);
			$this->ft_filename=$filename;
			$this->ft_filesize=$file->size;
			$this->ft_filetype=$file->type;
			$file->saveAs('uploads/'.$filename);
		}
		return parent::beforeSave();
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ft_id' => 'Ft',
			'ft_filename' => 'Ft Filename',
			'ft_kode' => 'Ft Kode',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ft_id',$this->ft_id);
		$criteria->compare('ft_filename',$this->ft_filename,true);
		$criteria->compare('ft_kode',$this->ft_kode);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}